<?php


namespace App\Transformers\System;
use App\Models\SystemAdmin;
use App\Transformers\Article\ArticlesTransformer;
use App\Transformers\MerchantRegistersTransformer;
use App\Transformers\SystemNotice\SystemNoticeAdminTransformer;
use League\Fractal\TransformerAbstract;

class SystemAdminTransformer extends TransformerAbstract
{
    protected  $availableIncludes = ['article','systemLog','systemNoticeAdmin','mer'];
    public function transform(SystemAdmin $data)
    {
        return [
            'id' => $data->id,
            'account' => $data->account ?? '',
            'identity' => $data->account ?? '',
            'avatar' => $data->avatar ?? '',
            'avatar_url' => 'https://placeimg.com/640/480/any',
            'real_name' => $data->real_name ?? '',
            'roles' => $data->roles ?? '',
            'last_ip' => $data->last_ip ?? '',
            'last_time' => $data->last_time ?? '',
            'level' => $data->level ?? '',
            'login_count' => $data->login_count ?? '',
            'status' => $data->status ?? '',
            'created_at' => $data->created_at ? $data->created_at->format("Y-m-d H:i:s") : '',
            'updated_at' => $data->updated_at ? $data->updated_at->format("Y-m-d H:i:s") : '',
        ];
    }

    /**
     * 管理员所管理的文章
     */
    public function includearticle(SystemAdmin $systemAdmin){
        return $this->collection($systemAdmin->article,new ArticlesTransformer());
    }


    /**
     * 管理员所关联的所有操作记录
     */
    public function includesystemLog(SystemAdmin $systemAdmin){
        return $this->collection($systemAdmin->systemLog,new SystemLogTransformer());
    }

    /**
     * 管理员管理的所有文章
     */
    public function includesystemNoticeAdmin(SystemAdmin $systemAdmin){
        return $this->collection($systemAdmin->systemNoticeAdmin,new SystemNoticeAdminTransformer());
    }

}

